package com.sky.controller.admin;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RequestMapping(value = "/admin/shop")
@RestController("AdminShopController")//避免bean的名字相同
@Api(tags = "商铺相关接口")
public class ShopController {
    @Autowired
    private RedisTemplate  redisTemplate;

    /**
     * 设置商铺状态
     * @param status
     * @return
     */
    @ApiOperation("设置商铺状态")
    @PutMapping("/{status}")
    public Result setShopStatus(@PathVariable Integer status){
        log.info("设置商铺状态:{}",status==1?"营业中":"打烊中");
        redisTemplate.opsForValue().set("SHOP_STATUS",status);
        return Result.success();
    }

    /**
     * 获取商铺状态
     * @return
     */
    @ApiOperation("获取商铺状态")
    @GetMapping("/status")
    public Result<Integer> getShopStatus(){
        log.info("获取商铺状态");
        Integer shopStatus = (Integer) redisTemplate.opsForValue().get("SHOP_STATUS");
        return Result.success(shopStatus);
    }
}
